<?php
defined('IN_TS') or die('Access Denied.');
/*
 * 增加分类
*/
switch($ts){
	//分类列表
	case "list":
		$arrCate = $new['ask']->findAll('ask_cate');
		
		include template("admin/cate_list");
		break;
	//分类添加
	case "add":
		include template("admin/cate_add");
		break;
	case "add_do":
		$arrData = array(
		'catename'	=> trim($_POST['catename']),
		'catedesc'	=> trim($_POST['catedesc'])
		);
		$db->insertArr($arrData,dbprefix.'ask_cate');
		header("Location: ".SITE_URL."index.php?app=ask&ac=admin&mg=cate&ts=list");
		break;
	case "edit":
		$cateid = intval($_GET['cateid']);
		$strCate = $new['ask']->find('ask_cate', array('cateid'=>$cateid));
		include template("admin/cate_edit");
		break;
	//分类修改执行
	case "edit_do":
		$cateid = intval($_POST['cateid']);
		$catename = trim($_POST['catename']);
		$catedesc = trim($_POST['catedesc']);
		$new['ask']->update('ask_cate',array('cateid'=>$cateid), array('catename'=>$catename, 'catedesc'=>$catedesc));
		header("Location: ".SITE_URL."index.php?app=ask&ac=admin&mg=cate&ts=list");
		break;
	//分类删除
	case "del":
	
		$cateid = intval($_GET['cateid']);
	
		//首先判断该分类下 有没有问答话题
		$isTopicCate = $new['ask']->findCount('ask_topic_cate',array(
			'cateid'=>$cateid,
		));
		
		if($isTopicCate==0){
			$new['ask']->delete('ask_user_cate',array(
				'cateid'=>$cateid,
			));
			$new['ask']->delete('ask_cate',array(
				'cateid'=>$cateid,
			));
			
			qiMsg("分类删除成功！");
		}else{
			qiMsg("此分类下有问答，不允许删除！");
		}
	
	
		
	
		break;
}